package com.qf.j2205.service.impl;


import com.qf.j2205.dao.AdminInfoMapper;
import com.qf.j2205.entity.AdminInfo;
import com.qf.j2205.service.AdminInfoService;
import com.qf.j2205.util.MybitesUtil;

/**
 * @ClassName AdminInfoServiceImpl
 * @Description TODO
 * @Author Windy
 * @Date 2022/8/15 17:30
 * @Version 1.0
 **/
public class AdminInfoServiceImpl implements AdminInfoService {
    @Override
    public AdminInfo isLogin(String username, String password) {
        //通过工具类创建mapper实例
        AdminInfoMapper mapper = MybitesUtil.getSession().getMapper(AdminInfoMapper.class);
        //调用查询方法获取AdminInfo对象
        AdminInfo adminInfo = mapper.getAdminInfoMapByUsername(username);
        //关闭连接
        MybitesUtil.closeAll();
        if(adminInfo != null&&adminInfo.getAPassword().equals(password)){
            return adminInfo;
        }
        return null;

    }

    /**
     * 更新用户
     * @param admin
     * @return
     */
    @Override
    public boolean updateAdmin(AdminInfo admin){
        //通过工具类创建mapper实例
        AdminInfoMapper mapper = MybitesUtil.getSession().getMapper(AdminInfoMapper.class);
        //调用查询方法获取AdminInfo对象
        int i = mapper.updateAdmin(admin);
        if (i >= 0) {
            MybitesUtil.commitWork();
            MybitesUtil.closeAll();
            return true;
        }
        MybitesUtil.rollbackWork();
        MybitesUtil.closeAll();
        return false;
    }
}
